import { DataTypes } from "sequelize";
import sequelize from "./db";
import UserModel from "./UserModel";
// import JournalsModel from "./JournalModel";

const MarkerModel = sequelize.define("marker_poi", {
  u_id: {
    type: DataTypes.INTEGER,
    references: {
      model: UserModel,
      key: "id",
    },
    primaryKey: true,
    unique: "compositeIndex",
    allowNull: false,
    comment: "用户id",
  },
  m_id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    unique: true,
    allowNull: false,
    autoIncrement: true, // 自增长
    comment: "marker的id",
  },
  id: {
    type: DataTypes.STRING(10),
    primaryKey: true,
    unique: "compositeIndex",
    allowNull: false,
    comment: "高德地图提供的地址唯一ID",
  },
  name: {
    type: DataTypes.STRING(30),
    allowNull: false,
  },
  address: {
    type: DataTypes.STRING(30),
    allowNull: false,
  },
  longitude: {
    type: DataTypes.DOUBLE,
    allowNull: false,
    comment: "经度",
  },
  latitude: {
    type: DataTypes.DOUBLE,
    allowNull: false,
    comment: "纬度",
  },
  citycode: {
    type: DataTypes.STRING(8),
    allowNull: false,
  },
  cityname: {
    type: DataTypes.STRING(20),
    allowNull: false,
  },
  pname: {
    type: DataTypes.STRING(10),
    allowNull: false,
  },
  postcode: {
    type: DataTypes.STRING(6),
    allowNull: false,
  },
  pcode: {
    type: DataTypes.STRING(6),
    allowNull: false,
  },
  adname: {
    type: DataTypes.STRING(30),
    allowNull: false,
  },
  adcode: {
    type: DataTypes.STRING(6),
    allowNull: false,
  },
  photos: {
    type: DataTypes.TEXT,
    allowNull: true,
    defaultValue: "",
  },
  is_open: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: 1, // 1: 公开，0: 仅自己可见
  },
  extdata: {
    type: DataTypes.TEXT,
    allowNull: true,
    defaultValue: "",
  },
});

// MarkerModel.hasMany(JournalsModel, {
//   sourceKey: "id",
//   foreignKey: "m_id"
// })

export default MarkerModel;
